home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 6 / CU Amiga Magazine's Super CD-ROM 06 (1996)(EMAP Images)(GB)(Track 1 of 4)[!][issue 1997-01].iso / cucd / prog / gnu-c / src / gcc-2.7.0-amiga / cppmain.c < prev    next >
C/C++ Source or Header  |  1995-08-24  |  3KB  |  120 lines

  1. /* CPP main program, using CPP Library.
  2.    Copyright (C) 1995 Free Software Foundation, Inc.
  3.    Written by Per Bothner, 1994-95.
  4.  
  5. This program is free software; you can redistribute it and/or modify it
  6. under the terms of the GNU General Public License as published by the
  7. Free Software Foundation; either version 2, or (at your option) any
  8. later version.
  9.  
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. GNU General Public License for more details.
  14.  
  15. You should have received a copy of the GNU General Public License
  16. along with this program; if not, write to the Free Software
  17. Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  18.  
  19.  In other words, you are welcome to use, share and improve this program.
  20.  You are forbidden to forbid anyone else to use, share and improve
  21.  what you give them.   Help stamp out software-hoarding!  */
  22.  
  23. #include "cpplib.h"
  24. #include <stdio.h>
  25.  
  26. #ifndef EMACS
  27. #include "config.h"
  28. #endif /* not EMACS */
  29.  
  30. extern char *getenv ();
  31.  
  32. cpp_reader parse_in;
  33. cpp_options options;
  34.  
  35. #ifdef __amigados__
  36. #include <proto/exec.h>
  37. struct Task *amiga_task;
  38. #endif /* __amigados__ */
  39.  
  40. /* More 'friendly' abort that prints the line and file.
  41.    config.h can #define abort fancy_abort if you like that sort of thing.  */
  42.  
  43. void
  44. fancy_abort ()
  45. {
  46.   fatal ("Internal gcc abort.");
  47. }
  48.  
  49.  
  50. int
  51. main (argc, argv)
  52.      int argc;
  53.      char **argv;
  54. {
  55.   char *p;
  56.   int i;
  57.   int argi = 1;  /* Next argument to handle. */
  58.   struct cpp_options *opts = &options;
  59.  
  60. #ifdef __amigados__
  61.   {
  62.     char *envstr;
  63.  
  64.     if (envstr = getenv("GCCPRIORITY"))
  65.       if (((i = atoi(envstr)) > -20) && (i < 20)) opts->amiga_priority = i;
  66.   }
  67. #endif /* __amigados__ */
  68.  
  69.   p = argv[0] + strlen (argv[0]);
  70.   while (p != argv[0] && p[-1] != '/') --p;
  71.   progname = p;
  72.  
  73.   init_parse_file (&parse_in);
  74.   parse_in.data = opts;
  75.  
  76.   init_parse_options (opts);
  77.   
  78.   argi += cpp_handle_options (&parse_in, argc - argi , argv + argi);
  79.   if (argi < argc)
  80.     fatal ("Invalid option `%s'", argv[argi]);
  81.   parse_in.show_column = 1;
  82.  
  83. #ifdef __amigados__
  84.   Forbid();
  85.   amiga_task = FindTask(NULL);
  86.   Permit();
  87.   SetTaskPri(amiga_task, opts->amiga_priority);
  88. #endif /* __amigados__ */
  89.  
  90.   i = push_parse_file (&parse_in, opts->in_fname);
  91.   if (i != SUCCESS_EXIT_CODE)
  92.     return i;
  93.  
  94.   /* Now that we know the input file is valid, open the output.  */
  95.  
  96.   if (!opts->out_fname || !strcmp (opts->out_fname, ""))
  97.     opts->out_fname = "stdout";
  98.   else if (! freopen (opts->out_fname, "w", stdout))
  99.     cpp_pfatal_with_name (&parse_in, opts->out_fname);
  100.  
  101.   for (;;)
  102.     {
  103.       enum cpp_token kind;
  104.       if (! opts->no_output)
  105.     {
  106.       fwrite (parse_in.token_buffer, 1, CPP_WRITTEN (&parse_in), stdout);
  107.     }
  108.       parse_in.limit = parse_in.token_buffer;
  109.       kind = cpp_get_token (&parse_in);
  110.       if (kind == CPP_EOF)
  111.     break;
  112.     }
  113.  
  114.   cpp_finish (&parse_in);
  115.  
  116.   if (parse_in.errors)
  117.     exit (FATAL_EXIT_CODE);
  118.   exit (SUCCESS_EXIT_CODE);
  119. }
  120.